package com.leo.javase.thread.itcast;


public class MultiThreadShareData {

	public static void main(String[] args) {
		final ShareData data = new ShareData();
		for(int i=0; i<2; i++){
			new Thread(new Runnable() {
				@Override
				public void run() {
					data.increment();
				}
			}).start();
		}
		for(int i=0; i<2; i++){
			new Thread(new Runnable() {
				@Override
				public void run() {
					data.decrement();
				}
			}).start();
		}
		System.out.println(data.count);
	}

}
class ShareData{
	int count = 0;
	
	public synchronized void increment(){
		count++;
	}
	
	public synchronized void decrement(){
		count--;
	}
}